package com.sls.game.dao.eightooj.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.eightooj.EightZeroJProductDAO;
import com.sls.game.dao.impl.SuperDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.eightooj.EightZeroJProduct;

@Repository("eightZeroJProductDAO")
public class EightZeroJProductDAOImpl extends SuperDAO<EightZeroJProduct>
		implements EightZeroJProductDAO {

	@Override
	public void insert(EightZeroJProduct eightZeroJProduct) {
		this.getSqlSession()
				.insert("mybatis.xml.EightZeroJProductMapper.insert",
						eightZeroJProduct);

	}

	@Override
	public void update(EightZeroJProduct eightZeroJProduct) {
		this.getSqlSession()
				.update("mybatis.xml.EightZeroJProductMapper.update",
						eightZeroJProduct);

	}

	@Override
	public EightZeroJProduct queryById(String id) {
		return this.getSqlSession().selectOne(
				"mybatis.xml.EightZeroJProductMapper.selectByPrimaryKey", id);
	}

	@Override
	public Pagination<EightZeroJProduct> queryPage(
			EightZeroJProduct eightZeroJProduct) {
		Pagination<EightZeroJProduct> paginationList = null;
		Integer rowCount = queryRowCount(eightZeroJProduct);

		eightZeroJProduct.calculate();
		List<EightZeroJProduct> list = queryProductInfoList(eightZeroJProduct);
		paginationList = this
				.queryPagination(rowCount, list, eightZeroJProduct);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private Integer queryRowCount(EightZeroJProduct eightZeroJProduct) {
		Integer rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.EightZeroJProductMapper.queryRowCount",
				eightZeroJProduct);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private List<EightZeroJProduct> queryProductInfoList(
			EightZeroJProduct product) {
		List<EightZeroJProduct> list = this.getSqlSession().selectList(
				"mybatis.xml.EightZeroJProductMapper.queryEZJroductInfoList",
				product);
		return list;
	}

	@Override
	public EightZeroJProduct queryByProductId(String productId) {
		return this.getSqlSession().selectOne(
				"mybatis.xml.EightZeroJProductMapper.queryByProductId", productId);
	}

}
